#This is an example of how to embeebed RF+PAM in a script
from RFPAM import Unsupervised_Random_Forest
import numpy as np
import time

def run_example(dataset='data/test'):
    """Selects two observation randomly every 3 second and calculate their similarity 
    """
    rfpam = Unsupervised_Random_Forest()
    training_set = rfpam.read_data_from_file(dataset)
    print 'Training Forest'
    forest = rfpam.train_forest(training_set, 50)
    while True:
        index_array = np.arange(training_set.shape[0]) #create an array with the number of the row
        np.random.shuffle(index_array)
        observations = training_set[index_array[:2]]
        print '\n Calculating dissimilarity between: \n', observations
        diss, simi = rfpam.calculate_dissimilarity_with_forest(forest, observations)
        print '\nDissimilarity: \n', diss[0,1]
        print '\nSimilarity: \n', simi[0,1]
        time.sleep(3)

run_example()
